<?php
    /**
    *   $aPrame = array(
    *       'id' => 'nhasanxuat',
    *       'disabled' => 'true',
    *       'middle' => 'true',
    *       'width' => '250px',
    *       'dropdownImage' => 'small',
    *       'stringKey' => 'uri',
    *       'stringTitle' => 'title',
    *       'value' => 'con ga',
    *       'title' => 'con ga',
    *       'header' => 'nha san xuat',
    *       'headerWidth' => '32px',
    *       'useKey' => 'true',
    *       'isCategory' => 'true',
    *       'categories' => '...',
    *       'showData' => true,
    *       'data' => array(),
    *       'placeholder' => '',
    *       'aValue' => array(
    *               ....
    *           )
    *   );
    */
?>

<div class="custom_combobox" style="<?php if($template->get('middle')){echo 'vertical-align: middle;';} ?>">
    <?php
        if($template->get('header'))
        {
            if($template->get('headerWidth'))
            {
                echo '<input style="margin-right: -8px;width:'.$template->get('headerWidth').'" disabled type="text" value="'.$template->get('header').'">';
            }
            else
            {
                echo '<input style="margin-right: -8px;" disabled type="text" value="'.$template->get('header').'">';
            }
        }
    ?>
    <input placeholder="<?php if($template->get('placeholder')){echo $template->get('placeholder');} ?>" value="<?php if($template->get('title')){echo $template->get('title');} ?>" <?php if($template->get('disabled')){echo 'disabled';} ?> class="custom_combobox_title" <?php if($template->get('id')){echo 'id="'.$template->get('id').'_title" name="'.$template->get('id').'_title"';} ?> type="text" <?php if($template->get('width')){echo 'style="width:'.$template->get('width').'"';} ?>>
    <input value="<?php if($template->get('value')){echo $template->get('value');} ?>" <?php if($template->get('id')){echo 'id="'.$template->get('id').'" name="'.$template->get('id').'"';} ?> class="custom_combobox_val" type="hidden">
    <?php if($template->get('isCategory')){?>
        <input id="list_categories" type="hidden" name="list_categories" value="<?php if($template->get('categories')){echo $template->get('categories');} ?>">
        <input id="category_name" type="hidden" name="category_name" value="<?php if($template->get('title')){echo $template->get('title');} ?>">
        <?php } ?>

    <div class="dropdown_combobox" style="<?php if($template->get('dropdownImage')){ echo "background-image: url(".URL::getLink('image/'.$template->get('dropdownImage')).');';} ?>"><?php if(!$template->get('dropdownImage')){ echo '<i class="fa fa-angle-down"></i>';} ?></div>
    <?php
        if($template->get('aValue') && is_array($template->get('aValue')))
        {
            if(count($template->get('aValue')) < 6)
            {
                $height = count($template->get('aValue')) * 32 + 4;
            }
        }
    ?>
    <div class="option_panel" <?php if(isset($height)){echo 'style="height:'.$height.'px"';} ?>>
        <ul>
            <?php
                if($template->get('aValue') && is_array($template->get('aValue')))
                {
                    foreach($template->get('aValue') as $key => $value)
                    {
                        if(is_array($value))
                        {
                            // Hien thi hidden to save data
                            $sParam = '';
                            if($template->get('showData'))
                            {
                                if($template->get('data'))
                                {
                                    foreach($template->get('data') as $key)
                                    {
                                        $sParam = $sParam . '<input class="'.$template->get('id').'_'.$key.'" type="hidden" value="'.$value[$key].'">';             
                                    }
                                }
                            }
                            
                            // truong hoap category dac biet
                            if($template->get('isCategory'))
                            {
                                echo '<li 
                                pval="'.$value['sParentCategory'].$value[$template->get('stringKey')].'" 
                                val="'.$value[$template->get('stringKey')].'"
                                >'.$value[$template->get('stringTitle')].'</li>';
                            }
                            else
                            {
                                echo '<li 
                                class="'.($template->get('image') ? 'has_image' : '').'"  
                                val="'.$value[$template->get('stringKey')].'"
                                >'.$value[$template->get('stringTitle')].($template->get('image') ? '<div><img src="'.URL::getLink('upload/'.$value['image']).'" ></div>' : '').$sParam.'</li>';
                            }
                        }
                        else
                        {
                            if($template->get('useKey'))
                            {
                                echo '<li val="'.$key.'">'.$value.'</li>';
                            }
                            else
                            {
                                echo '<li val="'.$value.'">'.$value.'</li>';
                            }
                        }
                    }
                }
            ?>
        </ul>
        <?php if($template->get('aValue') && is_array($template->get('aValue')) && count($template->get('aValue')) > 6){ ?>
            <div class="scroll_bar">
                <div class="scroll"></div>
            </div>
            <?php } ?>
    </div>
    <div class="properity_panel">
        <input type="hidden" class="combobox_id" value="<?php echo $template->get('id'); ?>">
        <?php
            if($template->get('showData'))
            {
                if($template->get('data'))
                {
                    echo '<input id="'.$template->get('id').'_show_data" type="hidden" value="1">';
                    foreach($template->get('data') as $key)
                    {
                        echo '<input id="'.$template->get('id').'_'.$key.'" type="hidden">';
                    }
                }
            }
        ?>
    </div>
</div>